/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-09-28
 * Time: 21:58
 */
public class Solution {
    // 反转链表头插法
    public ListNode ReverseList (ListNode head) {
        // write code here
        // 头插法
        if (head == null) {
            return head;
        }
        ListNode cur = head;
        ListNode res = new ListNode(-1);
        res.next = head;
        while (cur.next != null) {
            ListNode temp = cur.next;
            cur.next = temp.next;
            temp.next = res.next;
            res.next = temp;
        }
        return res.next;
    }
}
